﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class BalanceCenter_AdminUpFiles : PageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }

    #region Web 窗体设计器生成的代码

    override protected void OnInit(EventArgs e)
    {
        isRequestLogin = true;
        RequestCompetences = Competences.BuildCompetencesList(Competences.FillContent);
        RequestLoginPage = "BalanceCenter/AdminUpFiles.aspx";

        base.OnInit(e);
    }

    #endregion

    protected void btnUpFiles_Click(object sender, EventArgs e)
    {
        if (tbFileTitle.Text.Trim() == "")
        {
            ShoveEL._Web.JavaScript.Alert(this.Page, "请输入文件标题");

            return;
        }

        string strFileFullName = System.IO.Path.GetFileName(this.FileUpLoad.PostedFile.FileName);
        if ((strFileFullName.Substring(strFileFullName.LastIndexOf('.') + 1, strFileFullName.Length - (strFileFullName.LastIndexOf('.') + 1)).ToLower() == "rar") || (strFileFullName.Substring(strFileFullName.LastIndexOf('.') + 1, strFileFullName.Length - (strFileFullName.LastIndexOf('.') + 1)).ToLower() == "zip"))
        {
            this.FileUpLoad.PostedFile.SaveAs(Server.MapPath("../UpFiles/") + strFileFullName);

            if (ShoveEL.Database.MSSQL.ExecuteNonQuery("insert into T_UpFiles(FileName, FileURL, Remark) values('" + tbFileTitle.Text.Trim() + "','" + strFileFullName + "','" + this.TextBox1.Text + "')") < 0)
            {
                ShoveEL._Web.JavaScript.Alert(this.Page, "上传文件失败!!");

                return;
            }
            else
            {
                //写入操作日志
                OperationLog Log = new OperationLog();

                Log._Memo = _User.Name + "上传文件《" + tbFileTitle.Text.Trim() + "》（" + strFileFullName + "）";
                Log._OpDateTime = DateTime.Now;
                Log._UserID = _User.ID;
                Log._UserIP = System.Web.HttpContext.Current.Request.UserHostAddress;

                Log.Add();
                //操作日志写入完成

                ShoveEL._Web.JavaScript.Alert(this.Page, "上传文件成功!", "AdminUpFileList.aspx");

                return;
            }
        }
        else
        {
            ShoveEL._Web.JavaScript.Alert(this.Page, "只允许上传rar、zip文件!");

            return;
        }        
    }
}